//获取应用实例
const app = getApp();
var gloData = app.globalData;
var codeString = '';

// 引入AES.js
var baseJs = require("../../common/base.js");
const dingyue = require("../../common/dingyue.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    type: '0',
    top: [{
      'title': '待付款',
      'active': true,
      'type': '0'
    },
    {
      'title': '已支付',
      'active': false,
      'type': '1'
    },
    {
      'title': '已完成',
      'active': false,
      'type': '2'
    }
    ],
    // 页数
    pageIndex: 1,
    // 所有商家列表
    orderList: [],
    orderList1: [],
    orderList2: [],
    state: '',
    //买家
    isbusinessOrder: 0,
    // 订单id
    orderid: '',
    // 输入邮费-弹框
    youfei: '',
    hiddensubmit: true,
    nocancel: false,
    // 退款
    tuikuan: '',
    hiddensubmit1: true,
    // 延长收货
    hiddensubmit2: true,
    // 确认收货
    hiddensubmit3: true,
    disabled: {
      type: "",
      value: "",
    },
    payFlag: true,//是否显示支付弹框
    paytype: 1,//选择的支付方式 ,默认是余额
    youfei: "",//邮费
    showPayPwdInput: false,//显示输入密码的提示框
    payFocus: true,  //密码框焦点
    isAlreadyPayPassword: '',//是否设置了支付密码
    payPasswords: "",//输入的密码
    orderType: '0',
    show: true,


    // 授权
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    powerFlag: true,
    phoneFlag: true,
    code: 'authMSG',
    orderNumber: 0,//用于订阅提醒
    goodsname: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.type) {
      this.setData({
        type: options.type,
        'top[1].active': true,
        'top[0].active': false
      })
    }
    this.setData({
      uid: wx.getStorageSync('uid'),
      orderid: options.orderid,
      isAlreadyPayPassword: wx.getStorageSync('isAlreadyPasswords'),
    })
    this.GetOrderList();
    wx.login({
      success(res) {
        //js调用登陆命令获取到code
        if (res.code) {
          codeString = res.code
          //通过code调用自己服务接口获取到openid
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
  },

  // 支付的详情的弹出框
  showgoPay(e) {
    console.log(e);
    var that = this;
    var youfei = e.currentTarget.dataset.type.YouFei //邮费的价格
    var OrderId = e.currentTarget.dataset.type.OrderId //订单id
    var goodsname = e.currentTarget.dataset.type.BuyGoodsName//商品名称，用于订阅提醒
    that.setData({
      youfei: youfei,//邮费
      payFlag: false, //弹出支付方式提示框
      orderid: OrderId,
      goodsname: goodsname
    })
    // console.log(youfei);
  },
  //点击去付款
  goPay: function () {
    var that = this;
    var uid = this.data.uid; //商户id
    var isAlreadyPayPassword = this.data.isAlreadyPayPassword;
    var paytype = this.data.paytype;
    // var orderid = this.data.orderid;
    // console.log(orderid);
    var orderType = this.data.orderType;
    // console.log(orderType)
    if (paytype == "1") {
      console.log("选择了余额");
      if (isAlreadyPayPassword == '1') {
        that.setData({
          showPayPwdInput: true, //显示密码输入框
          payFocus: true
        })
      } else {
        wx.showToast({
          title: "请先去设置支付密码！",
          icon: 'none',
          duration: 2000
        });
      }
    } else {
      console.log("000000");
      wx.showLoading({
        title: '加载中',
      })
    }
    if (paytype == '2') {
      // var orderType = this.data.orderType;
      console.log("微信");
      // 订单支付
      console.log(baseJs.api_Order + "PayOrder/" + this.data.orderid + "?" + "PayType=" + '3' + "&OrderType=" + orderType + "&UID=" + uid)
      wx.request({
        url: baseJs.api_Order + "PayOrder/" + this.data.orderid + "?" + "PayType=" + '3' + "&OrderType=3" + "&uid=" + uid,
        // console.log(baseJs.api_Order + "PayOrder/" + orderid + "?" + "PayType=" + '0' + "&OrderType=3"+"&uid="+uid)
        success: function (res) {
          console.log(res.data)
          var json= res.data.ResultData
          console.log(json)
          wx.hideLoading();
          if (res.data.ResultFlag == 1) {
            wx.requestPayment({
              timeStamp: res.data.ResultData.timeStamp,
              nonceStr: res.data.ResultData.nonceStr,
              package: res.data.ResultData.package,
              signType: res.data.ResultData.signType,
              paySign: res.data.ResultData.paySign,
              success(res) {
                console.log(res);
                wx.showToast({
                  title: '支付成功',
                  icon: 'none',
                  duration: 1000
                });
                // 订阅提醒
                dingyue.payYoufei("￥" + that.data.youfei, that.data.goodsname)
                // dingyue.payYoufei()
              },
              fail(res) {
                console.log(res);
                wx.showToast({
                  title: res.err_desc,
                  icon: 'none',
                  duration: 2000
                });
              }
            })
          } else {
            wx.showToast({
              title: res.data.ResultMsg,
              icon: 'none',
              duration: 2000
            });
          }
        }
      })
    }
  },

  // 输入密码的确认，余额支付
  surePasswords() {
    var that = this;
    var uid = this.data.uid;
    // var isAlreadyPayPassword = this.data.isAlreadyPayPassword;
    var payPasswords = this.data.payPasswords;
    // var paytype = this.data.paytype;
    var orderid = this.data.orderid;
    var orderType = this.data.orderType;
    console.log(orderType);
    console.log(orderid)
    wx.request({
      // 支付密码是否正确
      url: baseJs.api + baseJs.encryUrl("method=CheckMyTradePassword&UID=" + uid + "&TradePassword=" + payPasswords),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        console.log(json);
        if (json.ResultFlag == 1) {
          wx.showLoading({
            title: '加载中',
          })
          // 订单支付
          console.log(baseJs.api_Order + "PayOrder/" + orderid + "?" + "PayType=" + '0' + "&OrderType=3" + "&uid=" + uid)
          wx.request({
            url: baseJs.api_Order + "PayOrder/" + orderid + "?" + "PayType=" + '0' + "&OrderType=" + '3' + "&uid=" + uid,
            success: function (res) {
              console.log(res.data)
              wx.hideLoading();
              if (res.data.ResultFlag == 1) {
                wx.showToast({
                  title: res.data.ResultMsg,
                  icon: 'none',
                  duration: 2000
                });
                that.setData({
                  showPayPwdInput: false,
                  payFlag: true, //弹出支付方式提示框
                })
                // setTimeout(function () {
                //   wx.navigateBack({
                //     delta: 1,
                //   })
                //   // wx.navigateTo({
                //   //   url: '/packageA/myOrder/myOrder',
                //   // })
                // }, 1000)
                that.GetOrderList1()
                // 支付完成提醒卖家发货
                var youfei = "￥"+that.data.youfei
                var goodsname = that.data.goodsname
                dingyue.payYoufei(youfei, goodsname)
              } else {
                wx.showToast({
                  title: res.data.ResultMsg,
                  icon: 'none',
                  duration: 2000
                });
              }
            }
          })
        } else {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
      }
    })
  },

  // 支付弹出显示
  payShow: function () {
    this.setData({
      payFlag: !this.data.payFlag,
    })
  },
  // 选择的支付方式
  radioChange(e) {
    this.setData({
      paytype: e.detail.value,
    });
    console.log(e.detail.value);
  },
  //输入密码,监听
  inputPwd: function (e) {
    this.setData({
      payPasswords: e.detail.value
    });
  },
  // 密码框的取消
  cancelInputPasswords() {
    this.setData({
      showPayPwdInput: false,
      payFocus: false,
      payPasswords: '',
    });
  },



  // 顶部top
  topTap: function (e) {
    var top = this.data.top;
    var type = e.currentTarget.dataset.type;
    for (var i = 0, len = top.length; i < len; ++i) {
      if (top[i].type == type) {
        top[i].active = true;
      } else {
        top[i].active = false
      }
    }
    this.setData({
      top: top,
      type: type
    })

    // console.log(type);
    // console.log(top);
    this.GetOrderList1();
    wx.setStorageSync('type', e.currentTarget.dataset.type);

  },

  // fuzhi:function(){
  //   console.log("12132456");
  //   // wx.setClipboardData({
  //   //   data: '复制',
  //   //   success(res){
  //   //     console.log("复制成功",res);
  //   //     // wx.getClipboardData({
  //   //     //   success: (res) => {
  //   //     //     console.log(res.data);
  //   //     //   },
  //   //     // })
  //   //   }
  //   // })
  // },
  // 获取收银机订单信息
  GetOrderList: function () {
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var state = this.data.state;
    var type = this.data.type;
    var orderList = this.data.orderList;
    var orderList1 = this.data.orderList1;
    var orderList2 = this.data.orderList2;
    var isbusinessOrder = this.data.isbusinessOrder;

    if (isbusinessOrder == '0') {
      if (type == '0') {
        console.log(baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + pageIndex + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0')
        wx.request({
          url: baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + pageIndex + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0',
          success: function (res) {
            console.log(res.data)
            var json = res.data.ResultData;
            // console.log(json);

            for (var i = 0; i < json.length; i++) {
              orderList.push(json[i])
            }
            that.setData({
              orderList: orderList,
            })
            console.log(orderList);

            if (json.length == 10) {
              that.setData({
                state: 'loadMore',
              })
            } else if (json.length == 0 && pageIndex == 1) {
              that.setData({
                state: 'noData',
              })
            } else if (json.length < 10) {
              that.setData({
                state: 'noData',
              })
            }
            wx.setStorageSync('isbusinessOrder', '0')
          },
          fail(res) {
            console.log(res)
          }

        })
      } else if (type == '1') {
        console.log(baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + pageIndex + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0')
        wx.request({
          url: baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + pageIndex + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0',
          success: function (res) {
            // console.log(res.data)
            var json1 = res.data.ResultData;
            // console.log(json1);
            for (var i = 0; i < json1.length; i++) {
              orderList1.push(json1[i])
            }
            that.setData({
              orderList1: orderList1,
            })
            console.log(orderList1);

            if (json1.length == 10) {
              that.setData({
                state: 'loadMore',
              })
            } else if (json1.length == 0 && pageIndex == 1) {
              that.setData({
                state: 'noData',
              })
            } else if (json1.length < 10) {
              that.setData({
                state: 'noData',
              })
            }
            wx.setStorageSync('isbusinessOrder', '0')
          },
          fail(res) {
            console.log(res)
          }

        })
      } else {
        console.log(baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + pageIndex + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0')
        wx.request({
          url: baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + pageIndex + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0',
          success: function (res) {
            // console.log(res.data)
            var json2 = res.data.ResultData;
            // console.log(json2);
            for (var i = 0; i < json2.length; i++) {
              orderList2.push(json2[i])
            }
            that.setData({
              orderList2: orderList2,
            })
            console.log(orderList2);

            if (json2.length == 10) {
              that.setData({
                state: 'loadMore',
              })
            } else if (json2.length == 0 && pageIndex == 1) {
              that.setData({
                state: 'noData',
              })
            } else if (json2.length < 10) {
              that.setData({
                state: 'noData',
              })
            }
            wx.setStorageSync('isbusinessOrder', '0')
          },
          fail(res) {
            console.log(res)
          }

        })
      }
    }
  },
  // 刷新
  GetOrderList1: function () {
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var state = this.data.state;
    var type = this.data.type;
    var orderList = this.data.orderList;
    var orderList1 = this.data.orderList1;
    var orderList2 = this.data.orderList2;
    var isbusinessOrder = this.data.isbusinessOrder;
    if (isbusinessOrder == '0') {
      if (type == '0') {
        console.log(baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + '1' + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0')
        wx.request({
          url: baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + '1' + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0',
          success: function (res) {
            console.log(res.data)
            var json = res.data.ResultData;
            // console.log(json);
            orderList = [];
            for (var i = 0; i < json.length; i++) {
              orderList.push(json[i])
            }
            that.setData({
              orderList: orderList,
            })
            console.log(orderList);

            if (json.length == 10) {
              that.setData({
                state: 'loadMore',
              })
            } else if (json.length == 0 && pageIndex == 1) {
              that.setData({
                state: 'noData',
              })
            } else if (json.length < 10) {
              that.setData({
                state: 'noData',
              })
            }
          },
          fail(res) {
            console.log(res)
          }

        })
      } else if (type == '1') {
        // console.log(baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + '1' + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0')
        wx.request({
          url: baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + '1' + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0',
          success: function (res) {
            // console.log(res.data)
            var json1 = res.data.ResultData;
            // console.log(json1);
            orderList1 = [];
            for (var i = 0; i < json1.length; i++) {
              orderList1.push(json1[i])
            }
            that.setData({
              orderList1: orderList1,
            })
            console.log(orderList1);
            if (json1.length == 10) {
              that.setData({
                state: 'loadMore',
              })
            } else if (json1.length == 0 && pageIndex == 1) {
              that.setData({
                state: 'noData',
              })
            } else if (json1.length < 10) {
              that.setData({
                state: 'noData',
              })
            }
          },
          fail(res) {
            console.log(res)
          }

        })
      } else {
        console.log(baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + '1' + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0')
        wx.request({
          url: baseJs.api_Order + "GetOrderList/" + uid + "?" + "PageIndex=" + '1' + "&PageSize=" + '10' + "&OrderType=" + '1' + "&OrderState=" + type + "&IsBusinessOrder=" + '0',
          success: function (res) {
            // console.log(res.data)
            var json2 = res.data.ResultData;
            // console.log(json2);
            orderList2 = [];
            for (var i = 0; i < json2.length; i++) {
              orderList2.push(json2[i])
            }
            that.setData({
              orderList2: orderList2,
            })
            console.log(orderList2);

            if (json2.length == 10) {
              that.setData({
                state: 'loadMore',
              })
            } else if (json2.length == 0 && pageIndex == 1) {
              that.setData({
                state: 'noData',
              })
            } else if (json2.length < 10) {
              that.setData({
                state: 'noData',
              })
            }
          },
          fail(res) {
            console.log(res)
          }

        })
      }
    }
  },
  /**
    * 页面上拉触底事件的处理函数
    */
  onReachBottom: function () {
    this.data.pageIndex++;
    this.GetOrderList();
  },

  // 查看详情跳转-订单详情
  Orderdetails: function (event) {
    var id = event.currentTarget.id;

    // var type = event.currentTarget.dataset.type;
    console.log("00000");
    var type = wx.getStorageSync('type');
    console.log(type);
    var isbusinessOrder = wx.getStorageSync('isbusinessOrder')
    wx.navigateTo({
      url: '/packageA/Orderdetails/Orderdetails?orderid=' + id + '&Ordertype=' + type + '&isbusinessOrder=' + isbusinessOrder,
    })
  },


  // 自提-立即支付
  payMent: function (event) {
    var id = event.currentTarget.id;
    wx.navigateTo({
      url: '/packageA/Orderpayment/Orderpayment?orderid=' + id + "&show=1",
    })
  },


  // 邮费获取
  MaInput: function (e) {
    console.log(e)
    var youfei = this.data.youfei;
    this.setData({
      youfei: e.detail.value,
    })
  },


  // 输入邮费-modal弹框
  formSubmit(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var hiddensubmit = this.data.hiddensubmit;
    that.setData({
      hiddensubmit: !this.data.hiddensubmit,
      id: id
    })
    wx.setStorageSync('id', e.currentTarget.dataset.id);
  },
  // 弹框输入邮费-取消
  cancel: function () {
    this.setData({
      hiddensubmit: true,
      youfei: ""
    });
  },
  // 弹框输入邮费-确定
  confirm: function (e) {
    var that = this;
    var uid = this.data.uid;
    // var id = e.currentTarget.dataset.id;
    var youfei = this.data.youfei;
    var id = wx.getStorageSync('id');
    console.log(baseJs.api_Order + "UpdateOrderYouFei/" + uid + "/" + id + "?" + "YouFei=" + youfei);
    wx.request({
      url: baseJs.api_Order + "UpdateOrderYouFei/" + uid + "/" + id + "?" + "YouFei=" + youfei,
      success: function (res) {
        console.log(res.data)
        var json = res.data.ResultData;
        // console.log(json);
        if (res.data.ResultFlag == 1) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          this.GetOrderList1()
        }
        if (res.data.ResultFlag == 0) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
      }
    })
    this.setData({
      hiddensubmit: true
    });
  },



  // 退款获取
  refundInput: function (e) {
    console.log(e)
    var tuikuan = this.data.tuikuan;
    this.setData({
      tuikuan: e.detail.value,
    })
  },

  // 退款-modal弹框
  Refund(e) {
    console.log(e)
    var that = this;
    var id = e.currentTarget.dataset.id;
    var hiddensubmit1 = this.data.hiddensubmit1;
    that.setData({
      hiddensubmit1: !this.data.hiddensubmit1,
      id: id,
      orderid: e.currentTarget.dataset.value.OrderId,
      orderNumber: e.currentTarget.dataset.value.OrderNumber,//订单编号，用于订阅提醒
      goodsname: e.currentTarget.dataset.value.BuyGoodsName
    })
  },
  // 弹框输入退款理由--取消
  cancel1: function () {
    this.setData({
      hiddensubmit1: true,
      tuikuan: ""
    });
  },
  // 弹框输入退款理由--确定
  confirm1: function (e) {
    console.log(e);
    var that = this;
    var uid = this.data.uid;
    // var id = e.currentTarget.dataset.id;
    var id = that.data.orderid
    var tuikuan = this.data.tuikuan;
    // console.log(id)
    console.log(that.data.orderid)
    console.log(baseJs.api_Order + "ApplyOrderRefund/" + uid + "/" + id + "?" + "Describe=" + tuikuan);
    wx.request({
      url: baseJs.api_Order + "ApplyOrderRefund/" + uid + "/" + id + "?" + "Describe=" + tuikuan,
      success: function (res) {
        console.log(res.data)
        var json = res.data.ResultData;
        // console.log(json);
        if (res.data.ResultFlag == 1) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          that.GetOrderList1()
          // 申请退款想卖家发送信息
          var orderNumber = that.data.orderNumber
          var goodsname = that.data.goodsname
          var tmplIds = ['eXtajLhQBdZsRJFjKy3tLKg2FIEeB4Z4ovz0dGQ2NKQ']//退款模板id
          wx.requestSubscribeMessage({
            tmplIds: tmplIds,
            success(res) {
              console.log(res)
              dingyue.tuikuan(orderNumber, goodsname)
              //点击完成后就返回成功就行
            },
            fail:err=>{
              console.log(err);
            }
          })
        }
        if (res.data.ResultFlag == 0) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }

      }
    })
    this.setData({
      hiddensubmit1: true
    });
  },

  // 延长收货--modal弹框
  yanChang(e) {
    // console.log(e)
    var that = this;
    var id = e.currentTarget.dataset.id;
    var hiddensubmit2 = this.data.hiddensubmit2;
    that.setData({
      hiddensubmit2: !this.data.hiddensubmit2,
      id: id,
      orderid: e.currentTarget.dataset.value.OrderId
    })
  },
  // 延长收货--取消
  cancel2: function () {
    this.setData({
      hiddensubmit2: true
    });
  },
  // 延长收货--确定
  confirm2: function (e) {
    console.log(e);
    var that = this;
    var uid = this.data.uid;
    var id = that.data.orderid;
    console.log(id)
    console.log(baseJs.api_Order + "ExtendOrderTime/" + uid + "/" + id);
    wx.request({
      url: baseJs.api_Order + "ExtendOrderTime/" + uid + "/" + id,
      success: function (res) {
        console.log(res.data)
        var json = res.data.ResultData;
        // console.log(json);
        if (res.data.ResultFlag == 1) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          // setTimeout(function () {
          //   wx.navigateBack({
          //     delta: 1
          //   })
          // }, 1000)
          that.GetOrderList1()
        }
        if (res.data.ResultFlag == 0) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }

      }
    })
    this.setData({
      hiddensubmit2: true
    });
  },


  // 确认收货--modal弹框
  queRen(e) {
    console.log(e)
    var that = this;
    var id = e.currentTarget.dataset.id;
    var hiddensubmit3 = this.data.hiddensubmit3;
    that.setData({
      hiddensubmit3: !this.data.hiddensubmit3,
      id: id,
      orderid: e.currentTarget.dataset.value.OrderId
    })
  },
  // 确认收货--取消
  cancel3: function () {
    this.setData({
      hiddensubmit3: true
    });
  },
  // 确认收货--确定
  confirm3: function (e) {
    console.log(e);
    var that = this;
    var uid = this.data.uid;
    var id = that.data.orderid
    console.log(id)
    console.log(baseJs.api_Order + "ConfirmFinishOrder/" + uid + "/" + id);
    wx.request({
      url: baseJs.api_Order + "ConfirmFinishOrder/" + uid + "/" + id,
      success: function (res) {
        console.log(res.data)
        var json = res.data.ResultData;
        // console.log(json);
        if (res.data.ResultFlag == 1) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
          // setTimeout(function () {
          //   wx.navigateBack({
          //     delta: 1
          //   })
          // }, 1000)
          that.GetOrderList1();
        }
        if (res.data.ResultFlag == 0) {
          wx.showToast({
            title: res.data.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }

      }
    })
    this.setData({
      hiddensubmit3: true
    });
  },


  // // 授权登录
  bindAuthoriza: function () {
    var that = this;
    this.setData({
      powerFlag: false
    })
  },
  // //获取授权用户的信息
  // bindGetUserInfo(e) {
  //   wx.getSetting({
  //     success: res => {
  //       //如果经过授权
  //       if (res.authSetting['scope.userInfo']) {
  //         this.setData({
  //           hideBtn: true
  //         })
  //         //获取用户openid
  //         wx.getUserInfo({
  //           success: res => {
  //             var that = this;
  //             var uid = this.data.uid;
  //             this.data.userInfo = res.userInfo,
  //               this.data.userInfo.code = gloData.code,
  //               console.log(baseJs.api_Utils + "GetWXSmallProgeamUserOpenId/" + uid + "/" + codeString);
  //             wx.request({
  //               url: baseJs.api_Utils + "GetWXSmallProgeamUserOpenId/" + uid + "/" + codeString,
  //               success: function (res) {
  //                 console.log(res.data)
  //                 that.setData({
  //                   userInfo: app.globalData.userInfo,
  //                   uid: app.globalData.userInfo.uid,
  //                 })
  //               },
  //               fail(res) {
  //                 console.log(res.data)
  //               }
  //             })
  //           }
  //         })
  //       }
  //     }
  //   })
  // },
  // // 授权登录
  // powerTap: function () {
  //   this.setData({
  //     powerFlag: !this.data.powerFlag,
  //   })
  //   // wx.showToast({
  //   //   title: '授权成功',
  //   //   icon: 'none',
  //   //   duration: 2000
  //   // });
  // },

  // getUserInfo: function (e) {
  //   var that = this;
  //   var uid = this.data.uid;
  //   // console.log(e);
  //   app.globalData.userInfo = e.detail.userInfo
  //   this.setData({
  //     hasUserInfo: true,
  //   })
  // },

  getUserInfo: function (e) {
    var that = this;
    var uid = this.data.uid;
    // console.log(e);
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      hasUserInfo: true,
    })
  },


  //获取授权用户的信息
  bindGetUserInfo(e) {
    wx.getSetting({
      success: res => {
        //如果经过授权
        if (res.authSetting['scope.userInfo']) {
          this.setData({
            hideBtn: true
          })
          //获取用户openid
          wx.getUserInfo({
            success: res => {
              var that = this;
              var uid = this.data.uid;
              var resultData = this.data.resultData;
              this.data.userInfo = res.userInfo,
                this.data.userInfo.code = gloData.code,
                // 登录时的code
                // console.log(gloData.code);
                // console.log("method=GetSmallProgramOpenIdFromUserCode&Code=" + codeString + "&UID=" + this.data.uid)
                wx.request({
                  url: baseJs.api + baseJs.encryUrl("method=GetSmallProgramOpenIdFromUserCode&Code=" + codeString + "&UID=" + this.data.uid),
                  success: function (res) {
                    // console.log(res);
                    resultData = JSON.parse(baseJs.decryUrl(res.data));
                    console.log(resultData);
                    // if (app.globalData.userInfo) {
                    that.setData({
                      userInfo: app.globalData.userInfo,
                      // uid: app.globalData.userInfo.uid,
                    })
                    // console.log(gloData.code);
                    // } else {
                    // }
                    // console.log(JSON.parse(baseJs.decryUrl(res.data)))
                  }

                })
              // if (this.userInfoReadyCallback) {
              //   this.userInfoReadyCallback(res)
              // }
            }
          })
        }
      }
    })
  },

  // 授权登录
  powerTap: function () {
    this.setData({
      powerFlag: !this.data.powerFlag,
      payFlag: !this.data.payFlag
    })
    this.bindGetUserInfo()
    this.GetOrderList1()
    // // 授权成功后返回页面
    // wx.navigateBack({
    //   delta: 1
    // })
    // wx.navigateTo({
    //   url: '../mine/mine',
    // })
    wx.showToast({
      title: '授权成功，请重新支付。',
      icon: 'none',
      duration: 2000
    });
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
})